import EventEmitter from './EventEmitter'
import dayjs from 'dayjs'

export default class TimingMsg extends EventEmitter {
  constructor (hour = 15) {
    super()
    this.queKey = 'Notification'
    this.hour = hour
    this.timer = null
  }

  change (handler) {
    this.$once(this.queKey, handler)
  }

  start () {
    if (this.timer) clearInterval(this.timer)
    const hour = dayjs().hour()

    if (hour >= this.hour) return
    this.timer = setInterval(() => {
      if (dayjs().hour() === +this.hour) {
        console.log('时间展示')
        clearInterval(this.timer)
        this.timer = null
        this.$emit(this.queKey)
      }
    }, 1800000)
  }
}
